GBML manual / Backgrounds

background_priority

Sets which of the 4 hardware layers bg draws on - 0 is frontmost, 3 is backmost.

Game Boy: not available

Game Boy Color: not available

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

background_priority(bg, priority)

Arguments

NameType
bgbackground
priorityint

Returns

Nothing.

Description

Sets which of the 4 hardware layers bg draws on - 0 is frontmost, 3 is backmost. A no-op on nothing.

Priorities are already partly claimed by the current room: 0 is the shroud, if the room is shrouded. Its own tile layers claim the back of the range instead of the front - floors go to the back - counting down from the hardware's own back-most value: a room's first tile layer (normally its only one) sits on that back-most value itself, tying with a default-priority instance and, by the Game Boy Advance module's own rule, losing that tie to it. Anything not claimed this way is unclaimed by the engine itself, but may be shared with another background - or a room's own layer - at the same priority. Two things at the same priority do not conflict or crash; they simply tie-break by drawing order (a sprite always wins a tie against a background, hardware-guaranteed - see bg_priority), which for two backgrounds is your own authoring choice, not something this call resolves for you.

A newly created background starts at the back-most priority (3) until you call this. A background you show with draw_background keeps this priority. Without this call, its layer comes from the order of the draw calls in the event (starting from the drawing object's bg_priority); once you have called it, that layer is the one used, and the order of your calls only decides which of two backgrounds on the same layer is in front. A sprite on the same layer is always in front of the background. This call only ever reaches a background YOU made with background_create - there is no way to call it on a room's own tile-layer background from GBML source today, so a room's own floor cannot be re-prioritized from a project script, only compared against.

Example

backdrop = background_create(0, 0, ts_doc_dungeon);
if (backdrop != nothing) {
    background_priority(backdrop, 2);
}

Puts the new background at priority 2 - behind a shrouded room's own shroud (0, still the front-most layer), but now in front of an ordinary one-layer room's own floor (which sits on the back-most value, 3, not 1) - and in front of anything left at the hardware default too.

On the GBA

A no-op on `nothing`. Priorities are already partly claimed by the current room: 0 is the shroud, if the room is shrouded. Its own tile layers claim the BACK of the range instead of the front, counting down from 3: a room's first tile layer (its floor, normally its only one) sits on 3, and a later layer, if one is ever authored, takes 2, then 1. Anything not claimed this way is unclaimed by the engine itself, but may be shared with another background (or a room's own layer) at the same priority - two things at the same priority do not conflict or crash, they simply tie-break by drawing order, an authoring choice this call does not resolve for you. A newly created background starts at the back-most priority (3) until this is called. A background you show with draw_background keeps the layer you gave it here; without this call its layer comes from the order of the draw calls.

See also: background_createdraw_background